package kr.haggenna.item.controller;

import kr.haggenna.item.dao.ItemDao;
import kr.haggenna.item.domain.Item;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class GiftCardController {
	
	@Autowired
	private ItemDao itemDao;
	
	@RequestMapping("/giftCardList.do")
	public String form(){
		return "giftCardList"; 
	}
	
	@RequestMapping("/giftCardDetail.do")
	public ModelAndView detailForm(@RequestParam("itemNum")int itemNum){
		
		Item item = itemDao.getGiftcard(itemNum);
		int discountPrice = (int)(item.getItem_price()*0.9);
		ModelAndView mav = new ModelAndView();
		mav.setViewName("giftCardDetail");
		mav.addObject("discountPrice", discountPrice);
		mav.addObject("giftCard", item);
		return mav;
	}
}
